package com.han.hotelplat.cms.controller.holiday;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.han.hotelplat.comm.Constant;
import com.han.hotelplat.comm.ResponseWrapTo;
import com.han.hotelplat.comm.ResponseWrapTo.CodeType;
import com.han.hotelplat.comm.utils.DateUtil;
import com.han.hotelplat.pojo.holiday.Holiday;
import com.han.hotelplat.service.holiday.HolidayService;

@Controller
@RequestMapping("/cms/holiday")
public class CMSHolidayController {
	@Autowired
	private HolidayService holidayService;
	
	@ResponseBody
	@RequestMapping(value = "getAllHoliday", produces = "application/json;charset=UTF-8", method = { RequestMethod.GET,RequestMethod.POST  })
	public String getAllHoliday(){
		List<Holiday> li = holidayService.getAllHoliday();
		return new ResponseWrapTo(CodeType.success, "数据获取成功", li).toJson();
	}
	
	@ResponseBody
	@RequestMapping(value = "editHoliday", produces = "application/json;charset=UTF-8", method = { RequestMethod.GET,RequestMethod.POST  })
	public String editHoliday(String holidays){
		List<Holiday> jarry = JSONArray.parseArray(holidays,Holiday.class);
		holidayService.replaceHoliday(jarry);
		Constant.holidayMap.clear();
		for(Holiday h:jarry){
			Constant.holidayMap.put(DateUtil.formatYMD(h.getHolidaydate()), DateUtil.formatYMD(h.getHolidaydate()));
		}
		return new ResponseWrapTo(CodeType.success, "数据获取成功", jarry).toJson();
	}
}
